<?php
namespace app\index\controller\project;

class riskinfo extends base_project
{
    public $tableName = "ProjectRiskinfo";
    public function index()
    {
        $id=intval(input("risk_id"));
        $this->page(["risk_id"=>$id],10,"","id desc","plan");
       $riskinfo_status= model("CodeMap")->get_value("project_riskinfo_status");
        $data["riskinfo_status"] = array_column($riskinfo_status,"m_name","m_value");
        $this->assign($data);
        return view();
    }

    /**
     *  添加
     */
    public function add()
    {
        $model = model('ProjectRiskinfo');
        if (request()->instance()->isPost()) {
            $post = request()->instance()->param();
          
            $data["risk_id"] = $post["risk_id"];
            $data["title"] = $post["title"];
            $data["info"] = $post["info"];
            $data["status"] = $post["status"];    
            $data["project_id"] =$this->base_project_id;
            $data["uid"] =$this->member_id;
            $risk_info=model("ProjectRisk")->where(["id"=>intval($post["risk_id"])])->find();
            if(!empty($risk_info)){
                $data["plan_id"] =$risk_info->plan_id;
            }
            $ProjectRiskinfoModel = model("ProjectRiskinfo");
            $result = $this->operateData($data);
            if (empty($result)) {
                $this->error("操作失败");

            }
            $this->success("操作成功", url("/Index/Project/Riskinfo/index",array("risk_id"=> $post["risk_id"])));
        }
        $data["riskinfo_status"] = model("CodeMap")->get_value("project_riskinfo_status");
        $this->assign($data);
        return view();
    }

    /**
     *  修改
     */
    public function edit()
    {
        $ProjectRiskinfoModel = model('ProjectRiskinfo');
        if (request()->instance()->isPost()) {
            $post = request()->instance()->param();
           // $data["id"] = $post["id"];
            $data["risk_id"] = $post["risk_id"];
            $data["title"] = $post["title"];
            $data["info"] = $post["info"];
            $data["status"] = $post["status"];
            $data["create_time"] = $post["create_time"];
            $data["update_time"] = $post["update_time"];
            $data["delete_time"] = $post["delete_time"];
            $data["project_id"] = $post["project_id"];

            $map["id"] = $post["id"];
            $result = $this->operateData($data, $map);
            if (empty($result)) {
                $this->error("操作失败");

            }
            $this->success("操作成功", url("Index/Menu/index"));
        }

        $id = input("id");

        $data["info"] = $ProjectRiskinfoModel->get($id);

        $this->assign($data);
        return view();
    }

    public function del()
    {
        $id = input("id");
        if (empty($id)) {
            $this->error("删除失败");
        }
        $result = $this->delBase(["id" => intval($id)]);
        if ($result) {
            $this->success("删除成功");
        }
        $this->error("删除失败");
    }


    public  function done(){
        $id = input("id");
        if (empty($id)) {
            $this->error("操作失败");
        }
        $result =model("ProjectRiskinfo")->where(["id"=>intval($id)])->setField("status",1);
        if ($result) {
            $this->success("操作成功");
        }
        $this->error("操作失败");
    }


    public  function stop(){
        $ProjectRiskinfoModel = model('ProjectRiskinfo');
        if (request()->instance()->isPost()) {
            $post = request()->instance()->param();

            $id=intval( $post["id"]);
            if(empty($post["remarks"])){
                $this->error("操作失败,请填写备注信息");
            }
            $result =model("ProjectRiskinfo")->where(["id"=>intval($id)])->setField(["remarks"=>$post["remarks"],"status"=>2]);
            if ($result) {
                $this->success("操作成功");
            }
            $this->error("操作失败");
        }
        $id = input("id");

        $data["info"] = $ProjectRiskinfoModel->get($id);

        $this->assign($data);
        return view();
    }
}
